<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 12-8-25
 * Time: 下午1:34
 * To change this template use File | Settings | File Templates.
 */
class info extends MY_Controller
{
    public function index()
    {
        $id = max((int)$this->uri->rsegment(3, 0), 0);

        if (empty ($id)) {
            show_error('影片不存在!');
        }

        $this->load->model('movie');
        $movieData = $this->movie->getMovie($id, 1, 0, '*');//$mId, $limit = 20, $offset = 0, $field= "*", $where = null, $order = null

        if (empty ($movieData)) {
            show_error('影片不存在!');
        }

        $this->load->model('mod_category', 'category');
        $category = $this->category->get_category();
        $class_name =  $category[$movieData['class']]['name'];

        $downloadData = $this->movie->getDownLoad($id, 500);//var_dump($id);die;
        //print_r($downloadData);
        $vData = array(
            'title' => $movieData['china_name'] . ' ' . $class_name . ' ' . "在线观看 迅雷下载 电影1010",
            'data'  => $movieData,
            'class_name' => $class_name,
            'download' => $downloadData,
            "keywords" => $movieData['china_name'] .",". $class_name . ",". $movieData['type'] . ",". $movieData['version'],
            'description' => $movieData['china_name'] .",".$movieData['area'] . $class_name . $movieData['type'] . "在线观看,迅雷下载,电驴下载,剧情介绍",
        );
        $this->load->view('info', $vData);
        $this->saveHTML($id);
    }

    private function saveHTML($id)
    {
        $this->load->helper('directory');
        $path = FCPATH."resource/".formatID($id);
        recursiveMkdirDirectory($path);
        file_put_contents($path."{$id}.html", $this->formatHTML(), LOCK_EX);
    }

    /**
     * 记录浏览记录 / 数量
     *
     * @return mixed
     * @notice class 99 是首页, id 0 是首页，id 10000000 分类页
     */
    function visit()
    {
        $input['video_id'] = $this->input->get('id');
        $input['video_class'] = $this->input->get('class');
        $input['browse_ip'] = $this->input->ip_address();
        $input['ref'] = isset ($_SERVER['HTTP_REFERER']) ? trim($_SERVER['HTTP_REFERER'], '/') : config_item('base_url');//trim($this->input->server('HTTP_REFERER'), '/');

        if($input['ref'] == 'http://i.dy1010.com' || $input['ref'] == 'http://www.dy1010.com')
        {
            $input['type'] = 1;
        }
        elseif(strpos($input['ref'], 'dy1010.com') === 0)
        {
            $input['type'] = 2;
        }
        else
        {
            $input['type'] = 3;
        }

        $this->load->model('movie');
        $this->movie->visit($input['video_id']);
        //$this->movie->recordBrowseLog($input);//是否记录浏览日志
        return ;
    }
}